package com.yanfan.protocol.serialPort.controller;


import com.yanfan.protocol.serialPort.serialPort.ConvertHexStrAndStrUtils;
import com.yanfan.protocol.serialPort.serialPort.SerialPortManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  蚂蚁舞
 */
@Controller
@RequestMapping("/serialPort")
public class SerialPortController {

    @GetMapping("/list")
    @ResponseBody
    public List<String> listPorts() {
        List<String> portList = SerialPortManager.getSerialPortList();
        if(!portList.isEmpty()){
            return portList;
        }
        return null;
    }


    @PostMapping("/send/{hexData}")
    @ResponseBody
    public String sendPorts(@PathVariable("hexData") String hexData) {
        if (SerialPortManager.SERIAL_PORT_STATE){
            SerialPortManager.sendSerialPortData(ConvertHexStrAndStrUtils.hexStrToBytes(hexData));
            return "success";
        }
        return "fail";
    }



}

